import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.awt.event.ActionEvent;

public class RoomManger extends JFrame {
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_2;
	public RoomManger() {
		setTitle("\u623F\u5C4B\u7BA1\u7406");
		getContentPane().setLayout(null);
		
		JLabel lblNewLabel = new JLabel("\u623F\u5C4B\u7F16\u53F7");
		lblNewLabel.setBounds(91, 55, 54, 15);
		getContentPane().add(lblNewLabel);
		
		textField = new JTextField();
		textField.setBounds(175, 52, 119, 21);
		getContentPane().add(textField);
		textField.setColumns(10);
		
		JLabel lblNewLabel_1 = new JLabel("\u65B0\u65E7\u7A0B\u5EA6");
		lblNewLabel_1.setBounds(91, 96, 54, 15);
		getContentPane().add(lblNewLabel_1);
		
		textField_1 = new JTextField();
		textField_1.setBounds(175, 93, 119, 21);
		getContentPane().add(textField_1);
		textField_1.setColumns(10);
		
		JLabel lblNewLabel_2 = new JLabel("\u79DF\u91D1");
		lblNewLabel_2.setBounds(91, 143, 54, 15);
		getContentPane().add(lblNewLabel_2);
		
		textField_2 = new JTextField();
		textField_2.setBounds(175, 140, 119, 21);
		getContentPane().add(textField_2);
		textField_2.setColumns(10);
		
		JButton btnNewButton = new JButton("\u589E");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					new Dao().insertRoom(textField.getText(), textField_1.getText(), textField_2.getText());
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});
		btnNewButton.setBounds(64, 199, 66, 23);
		getContentPane().add(btnNewButton);
		
		JButton button = new JButton("\u5220");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					new Dao().deleteRoom(textField.getText());
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});
		button.setBounds(140, 199, 66, 23);
		getContentPane().add(button);
		
		JButton button_1 = new JButton("\u6539");
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					new Dao().updateRoom(textField.getText(),textField_2.getText());
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});
		button_1.setBounds(216, 199, 66, 23);
		getContentPane().add(button_1);
		
		JButton button_2 = new JButton("\u67E5");
		button_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					ResultSet result=new Dao().selectRoom(textField.getText());
					result.first();
					textField_1.setText(result.getString(2));
					textField_2.setText(result.getString(3));
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});
		button_2.setBounds(292, 199, 66, 23);
		this.setSize(500, 300);
		getContentPane().add(button_2);
	}
}
